package org.gdstash.character;

import org.gdstash.file.GDReader;
import org.gdstash.file.GDWriter;

import java.io.IOException;

public class GDCharFaction {
    private byte modified;
    private byte unlocked;
    private float value;
    private float positiveBoost;
    private float negativeBoost;

    public int getFactionReputation() {
        return (int) this.value;
    }

    public void setFactionReputation(final int reputation) {
        this.value = (float) reputation;
        if (reputation != 0) {
            this.modified = 1;
            this.unlocked = 1;
        }
    }

    public void read() throws IOException {
        this.modified = GDReader.readEncByte();
        this.unlocked = GDReader.readEncByte();
        this.value = GDReader.readEncFloat(true);
        this.positiveBoost = GDReader.readEncFloat(true);
        this.negativeBoost = GDReader.readEncFloat(true);
    }

    public void write() throws IOException {
        GDWriter.writeByte(this.modified);
        GDWriter.writeByte(this.unlocked);
        GDWriter.writeFloat(this.value);
        GDWriter.writeFloat(this.positiveBoost);
        GDWriter.writeFloat(this.negativeBoost);
    }

    public static int getByteSize() {
        int size = 0;
        ++size;
        ++size;
        size += 4;
        size += 4;
        size += 4;
        return size;
    }
}
